package com.socket.server;

import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class MinaServer {

    public static void main(String[] args){

        try {
            NioSocketAcceptor acceptor = new NioSocketAcceptor();
            acceptor.setHandler(new MyServerHander());
            acceptor.getFilterChain().addLast("codec",new ProtocolCodecFilter(new MyTextLinerFactory() ));
            acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE,5);
            acceptor.bind(new InetSocketAddress(8000));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
